//
//  AmodifiedViewController.m
//  TheRoadAD
//
//  Created by baixue on 16/8/4.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "AmodifiedViewController.h"

#import "ScreeningTunerConditionView.h"//筛选View

#import "TunerTableViewCell.h"//商家cell
#import "TunerModuleTableViewCell.h"//模块Cell

#import "TunerDetailViewController.h"//改装详情Controller
#import "CarAndBeautyViewController.h"//香车美女Controller

@interface AmodifiedViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation AmodifiedViewController
{
    ScreeningTunerConditionView *_screeningView;
}

 static NSString *const TunerTableViewCellID = @"TunerTableViewCell";
 static NSString *const TunerModuleTableViewCellID = @"TunerModuleTableViewCell";



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = BackgroundCOLOR;
    
    //设置导航栏
    [self setNav];
    
    //设置筛选条件View
    [self setScreeningView];
    
    //注册TableView
    [self registerTableView];
    
}
#pragma mark === 设置导航栏 ===
- (void)setNav{
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationItem.title = @"改装";
    
    
    UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_pinpai"] style:UIBarButtonItemStylePlain target:self action:@selector(moreConditions)];
    self.navigationItem.leftBarButtonItem = more;
    
    UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_find"] style:UIBarButtonItemStylePlain target:self action:@selector(searchTuner)];
    self.navigationItem.rightBarButtonItem = search;
}

#pragma mark === Nav更多筛选条件 ===
- (void)moreConditions{
    
}
#pragma mark === Nav搜索改装车 ===
- (void)searchTuner{
    
}

#pragma mark === 筛选View ===
- (void)setScreeningView{
    
    _screeningView = [[ScreeningTunerConditionView alloc] initWithFrame:CGRectMake(0, 64, Screen_Width, 104)];
    _screeningView.wgkArray = @[@"轮毂改装", @"音箱改装", @"灯光改装", @"车身改色", @"EEEE", @"FFFF", @"GGGG", @"HHHH"];
    _screeningView.xnkArray = @[@"ECU", @"刹车", @"增压套件", @"冷却", @"进气", @"排气"];
    _screeningView.fgArray = @[@"HF风格", @"街道风格", @"GT风格", @"拉力风格", @"DU风格"];
    _screeningView.backgroundColor = [UIColor whiteColor];
    _screeningView.wgClick = ^(NSString *condition){
        NSLog(@"%@", condition);
    };
    _screeningView.xnClick = ^(NSString *condition){
        NSLog(@"%@", condition);
    };
    _screeningView.fgClick = ^(NSString *condition){
        NSLog(@"%@", condition);
    };
    [_screeningView setView];
    
    [self.view addSubview:_screeningView];
}

#pragma mark === 注册TableView ===
- (void)registerTableView{
    [self.tableView registerNib:[UINib nibWithNibName:@"TunerTableViewCell" bundle:nil] forCellReuseIdentifier:TunerTableViewCellID];
    [self.tableView registerNib:[UINib nibWithNibName:@"TunerModuleTableViewCell" bundle:nil] forCellReuseIdentifier:TunerModuleTableViewCellID];
}

#pragma mark === TableViewDelegate ===
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3) {
        return 68 + Screen_Width * 7 / 15 + Screen_Width / 3 * 150 / 131 + 10;
    }
    return 100 + Screen_Width / 25 * 12;
}
//Reusable
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3) {
        TunerModuleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TunerModuleTableViewCellID];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    TunerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TunerTableViewCellID];
//    cell.headImg.image = [UIImage imageNamed:];
//    cell.name.text =
    cell.pic.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon_tu_%ld", indexPath.row % 3 + 1]];
//    cell.picNum.text = [NSString stringWithFormat:@"%@图", ];
    cell.spacing.constant = 0;
    cell.cellClick = ^(int temp){
        if (temp == 0) {
            NSLog(@"我想改");
        }else if (temp == 1){
            NSLog(@"评论");
        }else if (temp == 2){
            NSLog(@"分享");
        }else{
            
        }
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3) {
        CarAndBeautyViewController *car = [[CarAndBeautyViewController alloc] init];
        car.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:car animated:YES];
    }else{
        TunerDetailViewController *detail = [[TunerDetailViewController alloc] init];
        detail.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:detail animated:YES];
    }
}


- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,104 + 64 + 7, Screen_Width, Screen_Height - 104 - 64 - 49 - 7)style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = BackgroundCOLOR;
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end
